package res;

import graphics.NumberButton;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;

public class Resources {
	private static final int SQUARE_LENGTH = 3;
	private static final int IMG_WIDTH = 72;
	private static final int IMG_WIDTH_STEP = 72;
	private static final int IMG_HEIGHT = 79;
	private static final int IMG_HEIGHT_STEP = 80;
	
	public static InputStream getImageStream() {
		return Resources.class.getResourceAsStream("numberpanel.png");
	}
	
	public static InputStream getHighScoreStream() {
		return Resources.class.getResourceAsStream("highscores");
	}
	
	public static BufferedImage getCroppedImage(int no) throws IOException{
		BufferedImage img = ImageIO.read(getImageStream());
		return getCroppedImage(img, no);
	}
	
	public static BufferedImage getCroppedImage(BufferedImage img, int no) {
		int x = ((no-1)%SQUARE_LENGTH)*IMG_WIDTH_STEP;
		int y = ((no-1)/SQUARE_LENGTH)*IMG_HEIGHT_STEP;
		System.out.println("Getting sub image for "+no+" x "+x+" y "+y);
		return img.getSubimage(x, y, IMG_WIDTH, IMG_HEIGHT);
	}
}
